<%--
 *  File:    ControlGLAccountControlEdit.jsp
 *  @Author: Stephen Liu
 *  Date:    Monday, February 02, 2004

 *  Copyright (C) 2000 - 2001 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>

<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>
<%@ page import="com.oval.util.*" %>

<%@ page contentType ="text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<%
  Category cat = Category.getInstance("jsp.ControlGLAccountControlEdit");
  String strModuleName = "GL";
  String privilegeCode = "40109";
%>

<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/SessionTimeout.inc" %>
<%@ include file="/inc/Security.inc" %>

<html>
<head>
<title>controlglaccountcontroledit</title>
<PageFlow:CheckPageFlow pageName="controlglaccountcontroledit"/>
<%@ include file="/inc/InitEdit.inc" %>
<%
  HashMap glaccountinfo = (HashMap) pageContext.getAttribute("glaccountinfo");
  if (glaccountinfo == null)
    glaccountinfo = new HashMap();

  Vector accountcheckdetails = (Vector) pageContext.getAttribute("accountcheckdetails");
  if (accountcheckdetails == null)
    accountcheckdetails = new Vector();

  if (glaccountinfo.get("entitytype") != null && glaccountinfo.get("entitytype").toString().equals("1"))
    pageContext.setAttribute("glaccountlistid", glaccountinfo.get("entityid"));
%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="../css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="../js/ScriptLib.js"></script>
<script language="JavaScript" src="../js/Calendar.js"></script>
<script language="JavaScript">
function page_save() {
  if (!checkForm(frm))
    return;
  if (!formatDate(frm))
    return;
  if (!checkdate())
    return;
  formatCheckBox(frm);

  var curdate = dateTransform("<%= OvalTools.getDate() %>", "yyyy-MM-dd", "yyyy-MM-dd");
  var startdate = dateTransform(frm.startdate.value, "yyyy-MM-dd", "<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>");
  var enddate = dateTransform(frm.enddate.value, "yyyy-MM-dd", "<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>");
  if (frm.datecontrolflag.checked && ((!isEmpty(startdate) && curdate < startdate) || (!isEmpty(enddate) && curdate > enddate)))
    frm.status.value = 28;
  else if (frm.lockflag.checked)
    frm.status.value = 39;
  else frm.status.value = 41;

  if (Number(frm.entitytype.value) == 1) {
    var isneed, para1;
    for (var i = 0; i < <%=JspHelper.filterNull( accountcheckdetails.size() )%>; i ++) {
      isneed = eval("frm.isneed" + i).checked ? "1" : "0";
      para1 = isEmpty(eval("frm.para1" + i).value) ? "0" : "1";
      eval("frm.flagcontainer" + i).value = isneed + para1;
    }
  }

  frm.actionname.value = "save";
  isRunning = true;
  frm.submit();
}

function page_init() {
  with (frm) {
    var flag = flagcontainer.value;
    if (flag.length != 24)
      flag = "000000000000000000000000";

    if ((Number(fromtype.value) == 1) || (Number(fromtype.value) == 2 && Number(grade.value) > 1)) {
      datecontrolflag.disabled = flag.charAt(10) == "1";
      startdate.disabled = flag.charAt(10) == "1" && flag.charAt(11) == "1";
      enddate.disabled = flag.charAt(10) == "1" && flag.charAt(12) == "1";
      lockflag.disabled = flag.charAt(13) == "1";
      dailyaccountflag.disabled = flag.charAt(14) == 1;
      settlementflag.disabled = flag.charAt(15) == 1;
      forciblesettlementflag.disabled = !settlementflag.checked || flag.charAt(16) == 1;
      adjustflag.disabled = Number(fromtype.value) == 1 && flag.charAt(18);
    }
    else {
      startdate.disabled = !datecontrolflag.checked;
      enddate.disabled = !datecontrolflag.checked;
      forciblesettlementflag.disabled = !settlementflag.checked;
    }
  }
}

function checkdate() {
  var startdate = dateTransform(frm.startdate.value, "yyyy-MM-dd", "<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>");
  var enddate = dateTransform(frm.enddate.value, "yyyy-MM-dd", "<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>");
  if (startdate < 0) {
    alert("<%= message.getMessageDesc("VALUE_MUST_BE_DATE", label.getLabelName("L_BeginDate")) %>");
    frm.startdate.focus();
    return false;
  }
  if (enddate < 0) {
    alert("<%= message.getMessageDesc("VALUE_MUST_BE_DATE", label.getLabelName("L_EndDate")) %>");
    frm.enddate.focus();
    return false;
  }
  if (!isEmpty(frm.startdate.value) && !isEmpty(frm.enddate.value) && startdate > enddate) {
   alert("<%= message.getMessageDesc("VALUE_MUST_LESSTHAN", label.getLabelName("L_BeginDate"), label.getLabelName("L_EndDate")) %>");
   return false;
  }
  return true;
}
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="javascript:set_contentleft_height1(420);page_init()">
<form name="frm" method="post" action="../Dispatcher">
  <input type="hidden" name="pagename" value="controlglaccountcontroledit">
  <input type="hidden" name="actionname">

  <custom:hidden property="glaccountid"/>
  <custom:hidden property="glaccountlistid"/>
  <custom:hidden name="glaccountinfo" property="entitytype"/>
  <custom:hidden name="glaccountinfo" property="status"/>
  <custom:hidden name="glaccountinfo" property="fromtype"/>
  <custom:hidden name="glaccountinfo" property="grade"/>
  <custom:hidden name="glaccountinfo" property="flagcontainer"/>

  <input type="hidden" name="numrows" value="<%=JspHelper.filterNull( accountcheckdetails.size() )%>">

  <table id="topTable" border=0 cellpadding=0 cellspacing=0 width="100%">
    <tr>
      <td valign=top>
        <table border=0 cellpadding=1 cellspacing=0 width="100%">
          <tbody>
          <tr>
            <td bgcolor=#000000 style="PADDING-BOTTOM: 1px; PADDING-LEFT: 1px; PADDING-RIGHT: 1px; PADDING-TOP: 0px">
              <table bgcolor=#000000 border=0 cellpadding=0 cellspacing=0 width="100%">
               <tr>
                  <td  bgcolor=#ffffff style="PADDING-BOTTOM: 3px; PADDING-LEFT: 3px; PADDING-RIGHT: 3px; PADDING-TOP: 3px">
                    <div id=div2 style="HEIGHT: 245px; OVERFLOW: auto">
                      <table border="1" cellspacing="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" align="center" width="100%" cellpadding="1">
                        <tr>
                          <td class="td_right">
                            <a onclick="javascript:page_save()"><custom:button type="2" label="L_Save" border="0"/></a>
                          </td>
                        </tr>
                      </table>
                      <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
                        <tr class="deepblue-left">
                          <td class="title_center" colspan="5">
                            <div align="left"><%= label.getLabelName("L_CommonControlAttrib") %><%= label.getLabelName("L_Colon") %></div>
                          </td>
                        </tr>
                        <tr class="deepblue-left">
                          <td class="title_center" width="50"><%= label.getLabelName("L_IfControl") %></td>
                          <td class="title_center"><%= label.getLabelName("L_ControlItem") %></td>
                          <td class="title_center"><%= label.getLabelName("L_ControlParam") %></td>
                          <td class="title_center"><%= label.getLabelName("L_ControlItem") %></td>
                          <td class="title_center"><%= label.getLabelName("L_ControlParam") %></td>
                        </tr>
                        <tr>
                          <td>
                            <custom:checkbox name="glaccountinfo" property="datecontrolflag" checkFlag="1/0" style="border:0" onclick="javascript:startdate.disabled=!this.checked;enddate.disabled=!this.checked;"/>
                          </td>
                          <td><%= label.getLabelName("L_BeginDate") %><%= label.getLabelName("L_Colon") %></td>
                          <td>
                            <custom:text name="glaccountinfo" property="startdate" size="20" dataType="date" dataFormatName="dateformat" onblur="javascript:checkdate()"/>
                            <a onclick="javascript:if(!startdate.disabled)show_calendar('frm.startdate','<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>')"><custom:button type="3" label="L_Asterisk" imgsrc="Time.gif" border="0"/></a>
                          </td>
                          <td><%= label.getLabelName("L_EndDate") %><%= label.getLabelName("L_Colon") %></td>
                          <td>
                            <custom:text name="glaccountinfo" property="enddate" size="20" dataType="date" dataFormatName="dateformat" onblur="javascript:checkdate()"/>
                            <a onclick="javascript:if(!enddate.disabled)show_calendar('frm.enddate','<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>')"><custom:button type="3" label="L_Asterisk" imgsrc="Time.gif" border="0"/></a>
                          </td>
                        </tr>
                        <tr>
                          <td>
                            <custom:checkbox name="glaccountinfo" property="lockflag" checkFlag="1/0" style="border:0" onclick="javascript:frm.status.value=(this.checked?39:41);"/>
                          </td>
                          <td><%= label.getLabelName("L_LockFlag") %></td>
                          <td>&nbsp;</td>
                          <td>&nbsp;</td>
                          <td>&nbsp;</td>
                        </tr>
                        <tr>
                          <td>
                            <custom:checkbox name="glaccountinfo" property="dailyaccountflag" checkFlag="1/0" style="border:0"/>
                          </td>
                          <td><%= label.getLabelName("L_DailyAccountFlag") %></td>
                          <td>&nbsp;</td>
                          <td>&nbsp;</td>
                          <td>&nbsp;</td>
                        </tr>
                        <tr>
                          <td>
                            <custom:checkbox name="glaccountinfo" property="settlementflag" checkFlag="1/0" style="border:0" onclick="javascript:forciblesettlementflag.disabled=!this.checked"/>
                          </td>
                          <td><%= label.getLabelName("L_SettlementInfoNeed") %></td>
                          <td>
                            <custom:checkbox name="glaccountinfo" property="forciblesettlementflag" checkFlag="1/0" style="border:0"/>
                            <%= label.getLabelName("L_ForcibleControl") %> </td>
                          <td>&nbsp;</td>
                          <td>&nbsp;</td>
                        </tr>
                        <tr>
                          <td>
                            <custom:checkbox name="glaccountinfo" property="adjustflag" checkFlag="1/0" style="border:0"/>
                          </td>
                          <td><%= label.getLabelName("L_AdjustFlag") %></td>
                          <td>&nbsp;</td>
                          <td>&nbsp;</td>
                          <td>&nbsp;</td>
                        </tr>
                        <tr class="deepblue-left">
                          <td colspan="5" ><%= label.getLabelName("L_RestrictionAndPrealarm") %><%= label.getLabelName("L_Colon") %></td>
                        </tr>
                        <tr class="deepblue-left">
                          <td class="title_center" width="50"><%= label.getLabelName("L_IfControl") %></td>
                          <td class="title_center"><%= label.getLabelName("L_ControlItem") %></td>
                          <td class="title_center"><%= label.getLabelName("L_ControlParam") %></td>
                          <td colspan="2">
                            <div align="center"><%= label.getLabelName("L_Action1") %></div>
                          </td>
                        </tr>
                        <logic:iterate id="element" collection="<%= accountcheckdetails %>" indexId="idx">
                        <%
                          String flagcontainer = (String) ((HashMap) element).get("flagcontainer");
                          boolean disabled = false;
                          if (Integer.valueOf("1").equals(glaccountinfo.get("fromtype")) && "11".equals(flagcontainer))
                            disabled = true;
                          String onclick = "javascript:para1" + idx + ".disabled=!this.checked;_actiontype" + idx + ".disabled=!this.checked;";
                          boolean param_disabled = disabled || !"1".equals(((HashMap) element).get("isneed"));
                        %>
                        <custom:hidden name="element" property="accountcheckdetailid" colIndex="<%= idx %>"/>
                        <custom:hidden name="element" property="checkelementid" colIndex="<%= idx %>"/>
                        <custom:hidden name="element" property="glaccountid" colIndex="<%= idx %>"/>
                        <custom:hidden name="element" property="flagcontainer" colIndex="<%= idx %>"/>
                        <tr>
                          <td>
                            <custom:checkbox name="element" property="isneed" checkFlag="1/0" style="border:0" colIndex="<%=idx%>" disabled="<%=disabled%>" onclick="<%=onclick%>"/>
                          </td>
                          <td>
                            <custom:write name="element" property="name"/>
                          </td>
                          <td>
                            <input type="text" name="para1<%=JspHelper.filterNull( idx )%>" value="<custom:write name="element" property="para1"/>" <% if (param_disabled) { %>disabled<% } %>>
                          </td>
                          <td colspan="2">
                            <custom:select name="element" property="actiontype" changedName="_actiontype" optionsName="allactiontypes" optionValueKey="value" optionInnerTextKey="valuename" colIndex="<%= idx %>" disabled="<%= param_disabled %>" onchange="actiontype.value=this.value"/>
                            <custom:hidden name="element" property="actiontype" colIndex="<%= idx %>"/>
                          </td>
                        </tr>
                        </logic:iterate>
                      </table>
                    </div>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
          </tbody>
        </table>
      </td>
    </tr>
    <tr>
      <td class=summary_top height="6"></td>
    </tr>
    <tr>
      <%@ include file="ControlGLAccountEditBtn.inc" %>
    </tr>
  </table>
</form>
</body>
</html>
